﻿using System.Collections.Generic;
using UnityEngine;

namespace UnityModule
{

    public class SpriteAtlas
    {
        private Dictionary<string, Sprite> dicSprites = new Dictionary<string, Sprite>();
        public void AddSprite(string spName, Sprite sp)
        {
            dicSprites[spName] = sp;
        }
        public Sprite GetSprite(string spName)
        {
            Sprite temp = null;
            if (!string.IsNullOrEmpty(spName) && dicSprites.ContainsKey(spName))
            {
                temp = dicSprites[spName];
            }
            return temp;
        }
    }


    public class LoadedRes
    {
        public static float SURVIVE_TIME = 180;//资源建议存活时间
        public UnityEngine.Object obj;
        public SpriteAtlas sprites;
        public AsyncOperation sceneOperation;
        public LoadOptions options = LoadOptions.Auto;
        public float lastUseTime = Time.realtimeSinceStartup;
        /// <summary>
        /// 这里只管通过加载接口加载的缓存资源，依赖等不管
        /// 只清理通过接口加载的缓存资源
        /// </summary>
        /// <returns></returns>
        public bool CanAutoUnLoad()
        {
            return (Time.realtimeSinceStartup - lastUseTime >= SURVIVE_TIME);
        }
    }
}
